package asia.lics.web.controller.testPaper;

import asia.lics.common.annotation.Log;
import asia.lics.common.core.controller.BaseController;
import asia.lics.common.core.domain.AjaxResult;
import asia.lics.common.enums.BusinessType;
import asia.lics.common.utils.poi.ExcelUtil;
import asia.lics.system.domain.CTestPaperInfo;
import asia.lics.system.service.ICTestPaperInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ss-tutor
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/testPaperInfo/info")
public class CTestPaperInfoController extends BaseController {
    @Autowired
    private ICTestPaperInfoService cTestPaperInfoService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list/{paperId}")
    public AjaxResult list(CTestPaperInfo cTestPaperInfo, @PathVariable Long paperId) {
//        startPage();
        return AjaxResult.success(cTestPaperInfoService.selectCTestPaperInfoList(paperId, cTestPaperInfo));
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CTestPaperInfo cTestPaperInfo) {
        List<CTestPaperInfo> list = cTestPaperInfoService.selectCTestPaperInfoList(null, cTestPaperInfo);
        ExcelUtil<CTestPaperInfo> util = new ExcelUtil<CTestPaperInfo>(CTestPaperInfo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cTestPaperInfoService.selectCTestPaperInfoById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CTestPaperInfo cTestPaperInfo) {
        return toAjax(cTestPaperInfoService.insertCTestPaperInfo(cTestPaperInfo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CTestPaperInfo cTestPaperInfo) {
        return toAjax(cTestPaperInfoService.updateCTestPaperInfo(cTestPaperInfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cTestPaperInfoService.deleteCTestPaperInfoByIds(ids));
    }
}
